using System;
using System.Collections.Generic;
using System.Text;

using System.Web;
using System.Xml;

namespace Winsmarts.PPI.Common
{
    public class ProgramInputs
    {
        private bool isValid = false;
        private string url;
        private Operation currentOperation = Operation.Unspecified;

        private string fileName;

        public string FileName
        {
            get { return fileName; }
        }
	

        public Operation CurrentOperation
        {
            get { return currentOperation; }
        }

        private bool SetOperation(Operation newOperation)
        {
            if (currentOperation == Operation.Unspecified)
            {
                currentOperation = newOperation;
                return true;
            }
            else
            {
                Trace.WriteLine("Cannot specify two kinds of operations in one run", true);
                return false;
            }
        }

        public string Url
        {
            get { return url; }
        }
	

        public bool IsValid
        {
            get { return isValid; }
        }
	
        public ProgramInputs(string[] args)
        {
            if (args.Length == 0)
            {
                Trace.PrintHelp();
                return;
            }

            switch (args[0])
            {
                case "-help":
                    Trace.PrintHelp();
                    break;
                case "-url":
                case "-import" :
                case "-export" :
                case "-filename" :
                case "-importorder":
                    break;
                default:
                    Trace.WriteLine("Invalid inputs specified", true);
                    Trace.PrintHelp();
                    return;
            }

            // If we are this far, things must be going good :)
            // setup various other stuff here.

            for (int i = 0; i < args.Length; i++)
            {
                switch (args[i])
                {
                    case "-url":
                        url = args[i + 1];
                        i++;
                        break;
                    case "-import":
                        if (!SetOperation(Operation.Import)) return;
                        break;
                    case "-export":
                        if (!SetOperation(Operation.Export)) return;
                        break;
                    case "-filename":
                        fileName = args[i + 1];
                        i++;
                        break;
                    default:
                        Trace.WriteLine("Invalid operation specified to the program, exiting...", false);
                        break;
                }
            }

            // If we are here, everything executed well
            isValid = true;
        }
    }
}
